<?php

namespace App\Http\Controllers\XhApi;


use App\Repository\Orders\OrdersLogisticsRepository;
use App\Repository\XhApi\OrdersRepository;
use Illuminate\Http\Request;

class OrdersController extends BaseController
{
    public $repoist;

    public function __construct()
    {

        $this->repoist = new OrdersRepository();

    }

    public function index(Request $request)
    {
        $params = $request->all();
        $data = $this->repoist->index($params, $request->get('pageNum'), 10);
        if ($data['code'] == 200) {
            $data["ordersTypeList"] = config('xh.ordersTypeList');
            $data["ordersStatusList"] = config('card.ordersStatus');
            $data["ordersStatusList"][0] = '处理中';
            $data["ordersStatusList"][1] = '处理中';
            $data["ordersStatusList"][40] = '已签收';
            $data["ordersStatusList"][41] = '已签收';
        }
        return $data;
    }

// 修改地址
    public function editAddress(Request $request)
    {
        $ordersno = $request->get('ordersno');
        if (empty($ordersno)) {
            return $this->returnMsg(1, '单号异常');
        }
        return $this->repoist->editAddress($request->all());
    }

    public function detail(Request $request)
    {
        $ordersno = $request->get('ordersno');
        $memberId = $request->user->id ?? 0;
        $data = $this->repoist->detail($memberId, $ordersno);
        if ($data['code'] == 200) {
            $data["ordersTypeList"] = config('xh.ordersTypeList');
            $data["ordersStatusList"] = config('card.ordersStatus');
            $data["ordersStatusList"][0] = '处理中';
            $data["ordersStatusList"][1] = '处理中';
            $data["ordersStatusList"][40] = '已签收';
            $data["ordersStatusList"][41] = '已签收';
        }
        return $data;
    }

    public function logistics(Request $request)
    {
        if (!$request->get('number')) {
            return $this->returnMsg(1, '物流单号异常', []);
        }
        $RepoistLogistics = new OrdersLogisticsRepository();
        $data = $RepoistLogistics->getTimeline($request->get('number'));
        return $this->returnMsg(200, '查询完毕', $data);
    }

    public function buy(Request $request)
    {
        return $this->repoist->buy($request->all());
    }
}
